home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / gp_os9.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  3.4 KB  |  155 lines

  1. /* Copyright (C) 1989, 2000 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: gp_os9.c,v 1.3 2000/09/19 19:00:24 lpd Exp $ */
  20. /* OSK-specific routines for Ghostscript */
  21. #include "pipe_.h"
  22. #include "string_.h"
  23. #include "time_.h"
  24. #include "gx.h"
  25. #include "gp.h"
  26. #include <signal.h>
  27. #include <stdlib.h>        /* for exit */
  28. #include <sys/param.h>        /* for MAXPATHLEN */
  29.  
  30. int interrupted;
  31.  
  32. /* Forward declarations */
  33. private void signalhandler(P1(int));
  34. private FILE *rbfopen(P2(char *, char *));
  35.  
  36. /* Do platform-dependent initialization */
  37. void
  38. gp_init(void)
  39. {
  40.     intercept(signalhandler);
  41. }
  42.  
  43. /* Do platform-dependent cleanup. */
  44. void
  45. gp_exit(int exit_status, int code)
  46. {
  47. }
  48.  
  49. /* Exit the program. */
  50. void
  51. gp_do_exit(int exit_status)
  52. {
  53.     exit(exit_status);
  54. }
  55.  
  56. private void
  57. signalhandler(int sig)
  58. {
  59.     clearerr(stdin);
  60.     switch (sig) {
  61.     case SIGINT:
  62.     case SIGQUIT:
  63.         interrupted = 1;
  64.         break;
  65.     case SIGFPE:
  66.         interrupted = 2;
  67.         break;
  68.     default:
  69.         break;
  70.     }
  71. }
  72.  
  73. /* ------ Date and time ------ */
  74.  
  75. /* Read the current time (in seconds since Jan. 1, 1980) */
  76. /* and fraction (in nanoseconds). */
  77. #define PS_YEAR_0 80
  78. #define PS_MONTH_0 1
  79. #define PS_DAY_0 1
  80. void
  81. gp_get_realtime(long *pdt)
  82. {
  83.     long date, time, pstime, psdate, tick;
  84.     short day;
  85.  
  86.     _sysdate(0, &time, &date, &day, &tick);
  87.     _julian(&time, &date);
  88.  
  89.     pstime = 0;
  90.     psdate = (PS_YEAR_0 << 16) + (PS_MONTH_0 << 8) + PS_DAY_0;
  91.     _julian(&pstime, &psdate);
  92.  
  93.     pdt[0] = (date - psdate) * 86400 + time;
  94.     pdt[1] = 0;
  95.  
  96. #ifdef DEBUG_CLOCK
  97.     printf("pdt[0] = %ld  pdt[1] = %ld\n", pdt[0], pdt[1]);
  98. #endif
  99. }
  100.  
  101. /* Read the current user CPU time (in seconds) */
  102. /* and fraction (in nanoseconds).  */
  103. void
  104. gp_get_usertime(long *pdt)
  105. {
  106.     return gp_get_realtime(pdt);    /* not yet implemented */
  107. }
  108.  
  109. /* ------ Printer accessing ------ */
  110.  
  111. /* Open a connection to a printer.  A null file name means use the */
  112. /* standard printer connected to the machine, if any. */
  113. /* "|command" opens an output pipe. */
  114. /* Return NULL if the connection could not be opened. */
  115. FILE *
  116. gp_open_printer(char fname[gp_file_name_sizeof], int binary_mode)
  117. {
  118.     return
  119.     (strlen(fname) == 0 ? 0 :
  120.      fname[0] == '|' ? popen(fname + 1, "w") :
  121.      rbfopen(fname, "w"));
  122. }
  123.  
  124. FILE *
  125. rbfopen(char *fname, char *perm)
  126. {
  127.     FILE *file = fopen(fname, perm);
  128.  
  129.     file->_flag |= _RBF;
  130.     return file;
  131. }
  132.  
  133. /* Close the connection to the printer. */
  134. void
  135. gp_close_printer(FILE * pfile, const char *fname)
  136. {
  137.     if (fname[0] == '|')
  138.     pclose(pfile);
  139.     else
  140.     fclose(pfile);
  141. }
  142.  
  143. /* ------ File accessing -------- */
  144.  
  145. /* Set a file into binary or text mode. */
  146. int
  147. gp_setmode_binary(FILE * pfile, bool binary)
  148. {
  149.     if (binary)
  150.     file->_flag |= _RBF;
  151.     else
  152.     file->_flag &= ~_RBF;
  153.     return 0;
  154. }
  155.